/**
 * @author YinHang
 */
;(function () {
	function Physics() {
		
	};
	
	Physics.RectCollision = function (x1, y1, width1, height1, x2, y2, width2, height2) {
		if(x1 < x2 + width2 && x1 + width1 > x2
			&& y1 < y2 + height2 && y1 + height1 > y2)
			return true;
		return false;
	};
	
	Physics.Distance = function (x1, y1, x2, y2) {
		var dx = x1 - x2;
		var dy = y1 - y2;
        return Math.sqrt(dx * dx + dy * dy);
	};
	
	Physics.Angle = function (x1, y1, x2, y2) {
		var xd = x1 - x2;
		var yd = y1 - y2;
		var result = Math.abs(Math.atan( yd / xd ) / Math.PI * 180);
		if(xd > 0 && yd >= 0)
			return result;
		if(xd < 0 && yd >= 0)
			return 180 - result;
		if(xd < 0 && yd < 0)
			return 180 + result;
		if(xd > 0 && yd < 0)
			return 360 - result;
		if(xd == 0 && yd > 0)
			return 90;
		if(xd == 0 && yd < 0)
			return 270;
	};
	
	GameFramework.register(Physics);
})();
